/**
 * 初始化退货单据查询详情对话框
 */
var GoodsReturnListInfoDlg = {
    id:'returnGoodsTable',
    table:null,
    goodsReturnListInfoData: {}
};


/**
 * 初始化退货商品表格
 */
GoodsReturnListInfoDlg.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '退货商品ID', field: 'goodsId', visible: false, align: 'center', valign: 'middle'},
        {title: '退货数量', field: 'goodsNum', visible: true, align: 'center', valign: 'middle'},
        {title: '商品编码', field: 'goodsCode', visible: true, align: 'center', valign: 'middle'},
        {title: '商品名称', field: 'goodsName', visible: true, align: 'center', valign: 'middle'},
        {title: '商品型号', field: 'goodsModel', visible: true, align: 'center', valign: 'middle'},
        {title: '商品单价', field: 'goodsUnit', visible: true, align: 'center', valign: 'middle'},
        {title: '退货价格', field: 'goodsReturnPrice', visible: true, align: 'center', valign: 'middle'},
        {title: '退货总价', field: 'totalPrice', visible: true, align: 'center', valign: 'middle'},
        {title: '退货清单ID', field: 'returnGoodsListId', visible: false, align: 'center', valign: 'middle'},
        {title: '创建者', field: 'createBy', visible: false, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'createDate', visible: true, align: 'center', valign: 'middle'},
        {title: '更新者', field: 'updateBy', visible: false, align: 'center', valign: 'middle'},
        {title: '更新时间', field: 'updateDate', visible: false, align: 'center', valign: 'middle'},
        {title: '备注信息', field: 'remarks', visible: false, align: 'center', valign: 'middle'},
        {title: '删除标记（0：正常；1：删除）', field: 'delFlag', visible: false, align: 'center', valign: 'middle'}
    ];
};

/**
 * 清除数据
 */
GoodsReturnListInfoDlg.clearData = function () {
    this.goodsReturnListInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
GoodsReturnListInfoDlg.set = function (key, val) {
    this.goodsReturnListInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
GoodsReturnListInfoDlg.get = function (key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
GoodsReturnListInfoDlg.close = function () {
    parent.layer.close(window.parent.GoodsReturnList.layerIndex);
}

/**
 * 收集数据
 */
GoodsReturnListInfoDlg.collectData = function () {
    this
        .set('id')
        .set('goodsCode')
        .set('goodsModel')
        .set('goodsName')
        .set('goodsNum')
        .set('goodsReturnPrice')
        .set('totalPrice')
        .set('goodsUnit')
        .set('createBy')
        .set('createDate')
        .set('updateBy')
        .set('updateDate')
        .set('remarks')
        .set('delFlag')
        .set('returnGoodsListId')
        .set('goodsId');
}

/**
 * 提交添加
 */
GoodsReturnListInfoDlg.addSubmit = function () {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/goodsReturnList/add", function (data) {
        Feng.success("添加成功!");
        window.parent.GoodsReturnList.table.refresh();
        GoodsReturnListInfoDlg.close();
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.goodsReturnListInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
GoodsReturnListInfoDlg.editSubmit = function () {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/goodsReturnList/update", function (data) {
        Feng.success("修改成功!");
        window.parent.GoodsReturnList.table.refresh();
        GoodsReturnListInfoDlg.close();
    }, function (data) {
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.goodsReturnListInfoData);
    ajax.start();
}

$(function () {
    //商品列表表格
    var defaultColunms = GoodsReturnListInfoDlg.initColumn();
    var returnListId = $("#returnListId").val();
    var table = new BSTable(GoodsReturnListInfoDlg.id, "/goodsReturnList/detail/"+returnListId, defaultColunms);
    table.setTableHeight(0);
    table.setShowRefresh(false);
    table.setShowColumns(false);
    table.setPaginationType("client");
    GoodsReturnListInfoDlg.table = table.init();

});
